<?php
// Module Definition
$module['name'] = 'Cron Jobs';
$module['description'] = 'Manage user cron jobs.';

switch($action) {
	case 'register':
		// Table structure for table `crons`
		$SQL = "
		CREATE TABLE `crons` (
		  `id` int(11) NOT NULL auto_increment,
		  `commands` mediumtext,
		  `month` char(2) NOT NULL default '',
		  `week` char(1) NOT NULL default '',
		  `day` char(1) NOT NULL default '',
		  `hour` char(2) NOT NULL default '',
		  `minute` char(2) NOT NULL default '',
		  `user` varchar(16) NOT NULL default '',
		  `domainid` varchar(10) NOT NULL default '',
		  `include` mediumtext,
		  `comment` mediumtext,
		  `fork` int(11) NOT NULL default '1',
		  `timeout` int(11) NOT NULL default '0',
		  `phpcommands` mediumtext,
		  `hook` mediumtext,
		  `lastrun` timestamp NOT NULL,
		  `lastrunoutput` mediumtext,
		  `lastrunresult` int(11) default NULL,
		  `createdby` varchar(16) NOT NULL default '',
		  PRIMARY KEY  (`id`)
		) TYPE=MyISAM;";
		mysql_query($SQL);

		$SQL = "INSERT INTO `crons` VALUES (2, NULL, '*', '*', '*', '3', '30', 'webcp', '', 'cron/logrotate.inc.phps', 'Run log rotation.', 1, 0, NULL, NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (3, NULL, '*', '*', '*', '15', '30', 'webcp', '', 'cron/logrotate.inc.phps', 'Run log rotation.', 1, 0, NULL, NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (4, NULL, '*', '*', '*', '3', '30', 'webcp', '', 'cron/webalizer.inc.phps', 'Run webalizer.', 1, 0, NULL, NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (6, NULL, '*', '*', '*', '3', '30', 'webcp', '', 'cron/schedbackups.inc.phps', 'Run scheduled backups.', 1, 0, '$schedbackups = \"Daily\";', NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (7, NULL, '*', '*', '1', '7', '30', 'webcp', '', 'cron/schedbackups.inc.phps', 'Run scheduled backups.', 1, 0, '$schedbackups = \"Weekly\";', NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (8, NULL, '*', '1', '1', '1', '30', 'webcp', '', 'cron/schedbackups.inc.phps', 'Run scheduled backups.', 1, 0, '$schedbackups = \"Monthly\";', NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (10, NULL, '*', '*', '*', '*', '*', 'webcp', '', 'cron/ttcheck.inc.phps', 'Check for waiting trouble tickets in mailbox.', 0, 0, NULL, NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (11, NULL, '*', '*', '*', '*', '*', 'webcp', '', 'cron/status.inc.phps', 'Indicate the backend is up and running.', 0, 0, NULL, NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (12, NULL, '*', '*', '*', '3', '30', 'webcp', '', 'cron/updatecount.inc.phps', 'Reset update counts daily.', 0, 0, NULL, NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		$SQL = "INSERT INTO `crons` VALUES (16, NULL, '*', '*', '1', '1', '1', 'webcp', '', 'cron/dbmaintenance.inc.phps', 'Run database maintenance on the web-cp database.', 0, 0, NULL, NULL, 0x303030302d30302d30302030303a30303a3030, '', NULL, '')";
		mysql_query($SQL);
		break;
	case 'unregister':
		$SQL = 'DELETE FROM properties WHERE name = "cron" AND user = "cron"';
		mysql_query($SQL);
		$SQL = 'DROP TABLE IF EXISTS crons';
		mysql_query($SQL);
		break;
	case 'enable':
		break;
	case 'disable':
		$SQL = 'DELETE FROM crons WHERE domainid != ""';
		mysql_query($SQL);
		break;
	case 'hook':
		register_hook('web:menu', 'cron_add_menu');
		register_hook('web:lang', 'cron_add_lang');
		register_hook('web:server:newaccount:table', 'cron_reseller_settings');
		register_hook('web:reseller:resellerset:table', 'cron_reseller_settings');
		register_hook('web:reseller:resellerinfo:table', 'cron_get_infotable');
		register_hook('web:reseller:newdomain:table', 'cron_domain_settings');
		register_hook('web:reseller:create', 'cron_set');
		register_hook('web:reseller:update', 'cron_set');
		register_hook('web:reseller:update:check', 'cron_check');

		register_hook('fetchdata:domain:cron', 'cron_fetch');
		register_hook('fetchdata:domain:*', 'cron_fetch');
		register_hook('fetchdata:reseller:cron', 'cron_fetch');
		register_hook('fetchdata:reseller:*', 'cron_fetch');
		register_hook('fetchdata:total:cron', 'cron_fetch_total');
		register_hook('fetchdata:total:*', 'cron_fetch_total');
		register_hook('fetchdata:alloc:cron', 'cron_fetch_alloc');
		register_hook('fetchdata:alloc:*', 'cron_fetch_alloc');

		register_hook('web:domain:domainset:table', 'cron_domain_settings');
		register_hook('web:domain:domaininfo:table', 'cron_get_infotable');
		register_hook('web:domain:create', 'cron_set');
		register_hook('web:domain:create:check', 'cron_domain_check');
		register_hook('web:domain:update', 'cron_set');
		register_hook('web:domain:update:check', 'cron_domain_check');
		register_hook('web:domain:cron', 'cron_create');
		break;
}
?>